﻿using FluentValidation;
using Masa.CqrsProject.Commands;

namespace Masa.CqrsProject.Validators
{

    /// <summary>
    /// 订单更新模块数据校验
    /// </summary>
    public class UpdateOrderCommandValidator : AbstractValidator<UpdateOrderCommand>
    {
        /// <summary>
        /// 数据校验-在事件发布前执行
        /// </summary>
        public UpdateOrderCommandValidator()
        {
            RuleFor(it => it.Id).NotEmpty().WithMessage("订单Id不能为空");

            RuleFor(it => it.OrderInfo.OrderPrice.Price).NotEmpty().WithMessage("订单价格不能为空");

            RuleFor(it => it.OrderInfo.OrderPrice.Price).GreaterThan(0).WithMessage("订单价格必须大于0");

            RuleFor(it => it.OrderInfo.OrderPrice.Price).InclusiveBetween(0, 9999999).WithMessage("订单价格异常");

            RuleFor(it => it.OrderInfo.OrderItems).NotEmpty().WithMessage("订单商品不能为空");
        }


    }
}
